---------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/Jeff/Dropbox/TermLimits/Replication/Models/Military/Conditional/Severity/PredictedValues.log
  log type:  text
 opened on:  12 Nov 2016, 22:10:36

. cd "/Users/Jeff/Dropbox/TermLimits/Replication/Models/Military/Conditional/Severity";
/Users/Jeff/Dropbox/TermLimits/Replication/Models/Military/Conditional/Severity

. **************************************************************;
. *Author: Jeff Carter                                         *;
. *Date: Saturday, May 23, 2015                              *;
. *Purpose: Simulating Predictions                *;
. **************************************************************;
. ** Need Legend for Probabilities and Differences  **;
. use "/Users/Jeff/Dropbox/TermLimits/Replication/Models/Military/Conditional/Severity/SimData.dta";

. postutil clear;

. postfile mypost prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 prob_hat2 lo2 hi2 prob_hat3 lo3 hi3 prob_hat4 lo4 hi4 prob_hat5 lo5 h
> i5
>                 diff_hat0 diff_lo0 diff_hi0 diff_hat1 diff_lo1 diff_hi1 diff_hat2 diff_lo2 diff_hi2 
>                 prob_hat01 lo01 hi01 prob_hat11 lo11 hi11 prob_hat21 lo21 hi21 prob_hat31 lo31 hi31  prob_hat41 lo41 hi41
>  prob_hat51 lo51 hi51
>                 diff_hat01 diff_lo01 diff_hi01 diff_hat11 diff_lo11 diff_hi11 diff_hat21 diff_lo21 diff_hi21
>                 delta_hat delta_lo delta_hi delta_hat1 delta_lo1 delta_hi1 delta_hat2 delta_lo2 delta_hi2
>                 using PredictedValues, replace;
(note: file PredictedValues.dta not found)

. noisily display "start";
start

. local a=0 ;

. while `a' < .1 { ;
  2. {;
  3. scalar h_Accountable =   0  ;
  4. scalar h_LameDuck= 1  ;
  5. scalar h_Civilian = 0;
  6. scalar h_Military = 1;
  7. scalar h_Constant = 1;
  8. scalar h_Parliament = 0;
  9. scalar h_CivilWar = 0;
 10. scalar h_GDPpc =  12589.35;
 11. scalar h_Growth = 3.453132;
 12. scalar h_MajorPower = 0;
 13. scalar h_Borders = 2;
 14. scalar h_Mobilization =  -.0008714 ;
 15. scalar h_Time = 5;
 16.  scalar h_Rivalry = 0;
 17. scalar h_Female = 0;
 18. generate x_betahat0 = MG_b1*h_Accountable
>     + MG_b2*h_Civilian
>     + MG_b3*(h_Accountable*h_Civilian)
>     + MG_b4*h_Rivalry
>     + MG_b5*h_Borders
>     + MG_b6*h_Parliament
>     + MG_b7*h_Female 
>     + MG_b8*h_Time 
>     + MG_b9*(h_Time^2)
>     + MG_b10*(h_Time^3);
 19. generate x_betahat1 = MG_b1* h_LameDuck
>     + MG_b2*h_Civilian
>     + MG_b3*(h_LameDuck*h_Civilian)
>     + MG_b4*h_Rivalry
>     + MG_b5*h_Borders
>     + MG_b6*h_Parliament
>     + MG_b7*h_Female 
>     + MG_b8*h_Time 
>     + MG_b9*(h_Time^2)
>     + MG_b10*(h_Time^3);
 20. gen prob0=  1/(1+exp(x_betahat0-MG_b11));
 21. gen prob1=   (1/(1+exp(x_betahat0-MG_b12)))  -  (1/(1+exp(x_betahat0-MG_b11)))  ;
 22. gen prob2=   1- (1/(1+exp(x_betahat0-MG_b12)));
 23. gen prob3=  1/(1+exp(x_betahat1-MG_b11));
 24. gen prob4=  (1/(1+exp(x_betahat1-MG_b12)))  -  (1/(1+exp(x_betahat1-MG_b11)))  ;
 25. gen prob5=   1- (1/(1+exp(x_betahat1-MG_b12)));
 26.         gen diff0=prob3-prob0 ;
 27. gen diff1=prob4-prob1 ;
 28. gen diff2=prob5-prob2 ;
 29.         egen probhat0=mean(prob0) ;
 30. egen probhat1=mean(prob1) ;
 31. egen probhat2=mean(prob2) ;
 32. egen probhat3=mean(prob3) ;
 33. egen probhat4=mean(prob4) ;
 34. egen probhat5=mean(prob5) ;
 35. egen diffhat0=mean(diff0) ;
 36. egen diffhat1=mean(diff1) ;
 37. egen diffhat2=mean(diff2) ;
 38.  generate x_betahat01 =   MG_b1*h_Accountable
>     + MG_b2*h_Military
>     + MG_b3*(h_Accountable*h_Military)
>     + MG_b4*h_Rivalry
>     + MG_b5*h_Borders
>     + MG_b6*h_Parliament
>     + MG_b7*h_Female 
>     + MG_b8*h_Time 
>     + MG_b9*(h_Time^2)
>     + MG_b10*(h_Time^3);
 39.  generate x_betahat11 =   MG_b1* h_LameDuck
>     + MG_b2*h_Military
>     + MG_b3*(h_LameDuck*h_Military)
>     + MG_b4*h_Rivalry
>     + MG_b5*h_Borders
>     + MG_b6*h_Parliament
>     + MG_b7*h_Female 
>     + MG_b8*h_Time 
>     + MG_b9*(h_Time^2)
>     + MG_b10*(h_Time^3);
 40. gen prob01=  1/(1+exp(x_betahat01-MG_b11));
 41. gen prob11=   (1/(1+exp(x_betahat01-MG_b12)))  -  (1/(1+exp(x_betahat01-MG_b11)))  ;
 42. gen prob21=   1- (1/(1+exp(x_betahat01-MG_b12)));
 43. gen prob31=  1/(1+exp(x_betahat11-MG_b11));
 44. gen prob41=  (1/(1+exp(x_betahat11-MG_b12)))  -  (1/(1+exp(x_betahat11-MG_b11)))  ;
 45. gen prob51=   1- (1/(1+exp(x_betahat11-MG_b12)));
 46.         gen diff01=prob31-prob01 ;
 47. gen diff11=prob41-prob11 ;
 48. gen diff21=prob51-prob21 ;
 49.         egen probhat01=mean(prob01) ;
 50. egen probhat11=mean(prob11) ;
 51. egen probhat21=mean(prob21) ;
 52. egen probhat31=mean(prob31) ;
 53. egen probhat41=mean(prob41) ;
 54. egen probhat51=mean(prob51) ;
 55. egen diffhat01=mean(diff01) ;
 56. egen diffhat11=mean(diff11) ;
 57. egen diffhat21=mean(diff21) ;
 58.         gen delta= diff01-diff0 ;
 59. gen delta1 = diff11-diff1 ;
 60. gen delta2 = diff21-diff2 ;
 61. egen deltahat=mean(delta) ;
 62. egen deltahat1=mean(delta1) ;
 63. egen deltahat2=mean(delta2) ;
 64. tempname prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 prob_hat2 lo2 hi2 prob_hat3 lo3 hi3 prob_hat4 lo4 hi4 prob_hat5 lo5 hi5
>         diff_hat0 diff_lo0 diff_hi0 diff_hat1 diff_lo1 diff_hi1 diff_hat2 diff_lo2 diff_hi2
>         prob_hat01 lo01 hi01 prob_hat11 lo11 hi11 prob_hat21 lo21 hi21 prob_hat31 lo31 hi31 prob_hat41 lo41 hi41 prob_hat
> 51 lo51 hi51
>         diff_hat01 diff_lo01 diff_hi01 diff_hat11 diff_lo11 diff_hi11 diff_hat21 diff_lo21 diff_hi21
>         delta_hat delta_lo delta_hi delta_hat1 delta_lo1 delta_hi1 delta_hat2 delta_lo2 delta_hi2;
 65.             _pctile prob0, p(2.5,97.5) ;
 66.     scalar `lo0'=r(r1) ;
 67.     scalar `hi0'=r(r2) ;
 68.     _pctile prob1, p(2.5,97.5) ;
 69.     scalar `lo1'=r(r1) ;
 70.     scalar `hi1'=r(r2) ;
 71.     _pctile prob2, p(2.5,97.5) ;
 72.     scalar `lo2'=r(r1) ;
 73.     scalar `hi2'=r(r2) ;
 74.     _pctile prob3, p(2.5,97.5) ;
 75.     scalar `lo3'=r(r1) ;
 76.     scalar `hi3'=r(r2) ;
 77.     _pctile prob4, p(2.5,97.5) ;
 78.     scalar `lo4'=r(r1) ;
 79.     scalar `hi4'=r(r2) ;
 80.     _pctile prob5, p(2.5,97.5) ;
 81.     scalar `lo5'=r(r1) ;
 82.     scalar `hi5'=r(r2) ;
 83.             _pctile diff0, p(2.5,97.5) ;
 84.     scalar `diff_lo0'= r(r1) ;
 85.     scalar `diff_hi0'=r(r2) ;
 86.     _pctile diff1, p(2.5,97.5) ;
 87.     scalar `diff_lo1'= r(r1) ;
 88.     scalar `diff_hi1'=r(r2) ;
 89.     _pctile diff2, p(2.5,97.5) ;
 90.     scalar `diff_lo2'= r(r1) ;
 91.     scalar `diff_hi2'=r(r2) ;
 92.             scalar `prob_hat0'=probhat0 ;
 93.     scalar `prob_hat1'=probhat1 ;
 94.     scalar `prob_hat2'=probhat2 ;
 95.     scalar `prob_hat3'=probhat3 ;
 96.     scalar `prob_hat4'=probhat4 ;
 97.     scalar `prob_hat5'=probhat5 ;
 98.           scalar `diff_hat0'=diffhat0 ;
 99.     scalar `diff_hat1'=diffhat1 ;
100.     scalar `diff_hat2'=diffhat2 ;
101.     _pctile prob01, p(2.5,97.5) ;
102.     scalar `lo01'=r(r1) ;
103.     scalar `hi01'=r(r2) ;
104.     _pctile prob11, p(2.5,97.5) ;
105.     scalar `lo11'=r(r1) ;
106.     scalar `hi11'=r(r2) ;
107.     _pctile prob21, p(2.5,97.5) ;
108.     scalar `lo21'=r(r1) ;
109.     scalar `hi21'=r(r2) ;
110.     _pctile prob31, p(2.5,97.5) ;
111.     scalar `lo31'=r(r1) ;
112.     scalar `hi31'=r(r2) ;
113.             _pctile prob41, p(2.5,97.5) ;
114.     scalar `lo41'=r(r1) ;
115.     scalar `hi41'=r(r2) ;
116.     _pctile prob51, p(2.5,97.5) ;
117.     scalar `lo51'=r(r1) ;
118.     scalar `hi51'=r(r2) ;
119.             _pctile diff01, p(2.5,97.5) ;
120.     scalar `diff_lo01'= r(r1) ;
121.     scalar `diff_hi01'=r(r2) ;
122.     _pctile diff11, p(2.5,97.5) ;
123.     scalar `diff_lo11'= r(r1) ;
124.     scalar `diff_hi11'=r(r2) ;
125.     _pctile diff21, p(2.5,97.5) ;
126.     scalar `diff_lo21'= r(r1) ;
127.     scalar `diff_hi21'=r(r2) ;
128.     scalar `prob_hat01'=probhat01 ;
129.     scalar `prob_hat11'=probhat11 ;
130.     scalar `prob_hat21'=probhat21 ;
131.     scalar `prob_hat31'=probhat31 ;
132.     scalar `prob_hat41'=probhat41 ;
133.     scalar `prob_hat51'=probhat51 ;
134.     scalar `diff_hat01'=diffhat01 ;
135.     scalar `diff_hat11'=diffhat11 ;
136.     scalar `diff_hat21'=diffhat21 ;
137.     _pctile delta, p(2.5,97.5) ;
138.     scalar `delta_lo'= r(r1) ;
139.     scalar `delta_hi'=r(r2) ;
140.     _pctile delta1, p(2.5,97.5) ;
141.     scalar `delta_lo1'= r(r1) ;
142.     scalar `delta_hi1'=r(r2) ;
143.     _pctile delta2, p(2.5,97.5) ;
144.     scalar `delta_lo2'= r(r1) ;
145.     scalar `delta_hi2'=r(r2) ;
146.             scalar `delta_hat'=deltahat;
147.     scalar `delta_hat1'=deltahat1;
148.     scalar `delta_hat2'=deltahat2;
149.  post mypost (`prob_hat0') (`lo0') (`hi0') (`prob_hat1') (`lo1') (`hi1') (`prob_hat2') (`lo2') (`hi2')
>         (`prob_hat3') (`lo3') (`hi3') (`prob_hat4') (`lo4') (`hi4') (`prob_hat5') (`lo5') (`hi5')
>         (`diff_hat0') (`diff_lo0') (`diff_hi0') (`diff_hat1') (`diff_lo1') (`diff_hi1') (`diff_hat2') (`diff_lo2') (`diff
> _hi2')
>         (`prob_hat01') (`lo01') (`hi01') (`prob_hat11') (`lo11') (`hi11') (`prob_hat21') (`lo21') (`hi21')
>         (`prob_hat31') (`lo31') (`hi31') (`prob_hat41') (`lo41') (`hi41') (`prob_hat51') (`lo51') (`hi51')
>         (`diff_hat01') (`diff_lo01') (`diff_hi01') (`diff_hat11') (`diff_lo11') (`diff_hi11') (`diff_hat21') (`diff_lo21'
> ) (`diff_hi21')
>                 (`delta_hat') (`delta_lo') (`delta_hi') (`delta_hat1') (`delta_lo1') (`delta_hi1') (`delta_hat2') (`delta
> _lo2') (`delta_hi2')
> 
>     ;
150.     } ;
151. drop    x_betahat0 x_betahat1
>         prob0 prob1 prob2 prob3 prob4 prob5
>         diff0 diff1 diff2
>         probhat0 probhat1 probhat2 probhat3 probhat4 probhat5
>         diffhat0 diffhat1 diffhat2
>         x_betahat01 x_betahat11
>         prob01 prob11 prob21 prob31 prob41 prob51
>         diff01 diff11 diff21
>         probhat01 probhat11 probhat21 probhat31 probhat41 probhat51
>         diffhat01 diffhat11 diffhat21
>         delta deltahat delta1 deltahat1 delta2 deltahat2;
152.     local a=`a'+ .1 ;
153.     display "." _c ;
154.     } ;
.
. display "" ;


.  postclose mypost ;

. use PredictedValues, clear;

. sum;

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
   prob_hat0 |         1    .9504526           .   .9504526   .9504526
         lo0 |         1    .9290065           .   .9290065   .9290065
         hi0 |         1    .9670326           .   .9670326   .9670326
   prob_hat1 |         1    .0383831           .   .0383831   .0383831
         lo1 |         1    .0253013           .   .0253013   .0253013
-------------+--------------------------------------------------------
         hi1 |         1    .0554982           .   .0554982   .0554982
   prob_hat2 |         1    .0111643           .   .0111643   .0111643
         lo2 |         1    .0070462           .   .0070462   .0070462
         hi2 |         1    .0166696           .   .0166696   .0166696
   prob_hat3 |         1    .9744282           .   .9744282   .9744282
-------------+--------------------------------------------------------
         lo3 |         1    .9613376           .   .9613376   .9613376
         hi3 |         1    .9841498           .   .9841498   .9841498
   prob_hat4 |         1    .0199106           .   .0199106   .0199106
         lo4 |         1    .0123495           .   .0123495   .0123495
         hi4 |         1    .0300785           .   .0300785   .0300785
-------------+--------------------------------------------------------
   prob_hat5 |         1    .0056611           .   .0056611   .0056611
         lo5 |         1     .003301           .    .003301    .003301
         hi5 |         1    .0089137           .   .0089137   .0089137
   diff_hat0 |         1    .0239757           .   .0239757   .0239757
    diff_lo0 |         1    .0072288           .   .0072288   .0072288
-------------+--------------------------------------------------------
    diff_hi0 |         1    .0436508           .   .0436508   .0436508
   diff_hat1 |         1   -.0184725           .  -.0184725  -.0184725
    diff_lo1 |         1   -.0340073           .  -.0340073  -.0340073
    diff_hi1 |         1   -.0055378           .  -.0055378  -.0055378
   diff_hat2 |         1   -.0055032           .  -.0055032  -.0055032
-------------+--------------------------------------------------------
    diff_lo2 |         1   -.0102592           .  -.0102592  -.0102592
    diff_hi2 |         1   -.0016461           .  -.0016461  -.0016461
  prob_hat01 |         1    .9268847           .   .9268847   .9268847
        lo01 |         1     .894505           .    .894505    .894505
        hi01 |         1    .9520486           .   .9520486   .9520486
-------------+--------------------------------------------------------
  prob_hat11 |         1    .0562871           .   .0562871   .0562871
        lo11 |         1    .0368479           .   .0368479   .0368479
        hi11 |         1    .0815975           .   .0815975   .0815975
  prob_hat21 |         1    .0168283           .   .0168283   .0168283
        lo21 |         1    .0102597           .   .0102597   .0102597
-------------+--------------------------------------------------------
        hi21 |         1    .0256584           .   .0256584   .0256584
  prob_hat31 |         1    .9512374           .   .9512374   .9512374
        lo31 |         1    .9018242           .   .9018242   .9018242
        hi31 |         1    .9803544           .   .9803544   .9803544
  prob_hat41 |         1    .0377479           .   .0377479   .0377479
-------------+--------------------------------------------------------
        lo41 |         1    .0151907           .   .0151907   .0151907
        hi41 |         1    .0757085           .   .0757085   .0757085
  prob_hat51 |         1    .0110147           .   .0110147   .0110147
        lo51 |         1    .0042984           .   .0042984   .0042984
        hi51 |         1    .0231854           .   .0231854   .0231854
-------------+--------------------------------------------------------
  diff_hat01 |         1    .0243528           .   .0243528   .0243528
   diff_lo01 |         1   -.0255394           .  -.0255394  -.0255394
   diff_hi01 |         1    .0638206           .   .0638206   .0638206
  diff_hat11 |         1   -.0185392           .  -.0185392  -.0185392
   diff_lo11 |         1   -.0485841           .  -.0485841  -.0485841
-------------+--------------------------------------------------------
   diff_hi11 |         1    .0191593           .   .0191593   .0191593
  diff_hat21 |         1   -.0058136           .  -.0058136  -.0058136
   diff_lo21 |         1   -.0157131           .  -.0157131  -.0157131
   diff_hi21 |         1    .0062573           .   .0062573   .0062573
   delta_hat |         1    .0003771           .   .0003771   .0003771
-------------+--------------------------------------------------------
    delta_lo |         1   -.0516171           .  -.0516171  -.0516171
    delta_hi |         1    .0388129           .   .0388129   .0388129
  delta_hat1 |         1   -.0000666           .  -.0000666  -.0000666
   delta_lo1 |         1   -.0292451           .  -.0292451  -.0292451
   delta_hi1 |         1    .0392281           .   .0392281   .0392281
-------------+--------------------------------------------------------
  delta_hat2 |         1   -.0003105           .  -.0003105  -.0003105
   delta_lo2 |         1   -.0096888           .  -.0096888  -.0096888
   delta_hi2 |         1    .0117884           .   .0117884   .0117884

. saveold PredictedValues, replace;
file PredictedValues.dta saved

. log close;
      name:  <unnamed>
       log:  /Users/Jeff/Dropbox/TermLimits/Replication/Models/Military/Conditional/Severity/PredictedValues.log
  log type:  text
 closed on:  12 Nov 2016, 22:10:36
---------------------------------------------------------------------------------------------------------------------------
